//Accepted_B
#include <cstdio>

int n, m, k, i, j, s, x;

int main(){
	while((scanf("%d%d%d", &n, &m, &k)==3)&&(n+m+k)){
		j=i=0;
		s=1;
		while(k){
			if(  ((j==n)&&(s==1)) || ((j==1)&&(s==-1))  ){s *= -1;}
			j += s;//person
			++i;//action
			if(j==m){
				if( ((i%7)==0) || ((i%10)==7) ){--k;}
				else{
					x=i;
					while(x/=10){
						if(((x%10)==7)){
							--k;
							break;
						}
					}
				}
			}
		}
		printf("%d\n", i);
	}
	
	return 0;
}
